package top.idcard.agent.biz.entity;

import com.alibaba.fastjson.JSON;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author wx
 * @version 1.0
 * @date 2021/1/31 3:02 下午
 */
public abstract class Certification {

    private String no;

    public abstract CertificationEnum certificationType();

    public enum CertificationEnum{

        Native("0","大陆居民身份证", 40122 + 1),
        Hong("2","港澳台居住证", 40125 + 1),//
        Foreign("1","外国人永久居留证证", 39106 + 1);//国籍 1字节

        private String certificationValue;
        private String certificationName;
        private Integer byteLength;

        CertificationEnum(String certificationValue, String certificationName,Integer byteLength) {
            this.certificationValue = certificationValue;
            this.certificationName = certificationName;
            this.byteLength = byteLength;
        }

        public String getCertificationValue() {
            return certificationValue;
        }

        public String getCertificationName() {
            return certificationName;
        }

        public Integer getByteLength(){
            return byteLength;
        }

        public static CertificationEnum valueOf(Integer code){
            Optional<CertificationEnum> optional = Arrays.stream(CertificationEnum.values()).filter(item->code == Integer.valueOf(item.getCertificationValue())).findAny();
            if(optional.isPresent()){
                return optional.get();
            }
            return null;
        }
    }

    public abstract byte[] getBytes();

    public abstract Certification parseFrom(byte[] bytes);
}
